home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROGS.ZIP / IHELP.ICN < prev    next >
Text File  |  1992-09-28  |  3KB  |  91 lines

  1. ############################################################################
  2. #
  3. #    File:     ihelp.icn
  4. #
  5. #    Subject:  Program to give on-line help for Icon
  6. #
  7. #    Author:   Robert J. Alexander
  8. #
  9. #    Date:     December 5, 1989
  10. #
  11. ###########################################################################
  12. #
  13. #  ihelp -- Program to display "help" information
  14. #
  15. #       ihelp [-f helpfile] [item] [keyword ...]
  16. #
  17. #  The optional item name specifies the section of the help file which
  18. #  is to be displayed.  If no item name is specified a default section
  19. #  will be displayed, which usually lists the help items that are
  20. #  available.  An initial substring of the item name that differentiates
  21. #  it from other items is sufficient.
  22. #
  23. #  If keyword(s) are specified, then only lines that contain all of the
  24. #  keywords, in any order, are displayed.  The keywords do not have to
  25. #  correspond to whole words in the help text; only to text fragments.
  26. #
  27. #  All item name and keyword matches are case independent.
  28. #
  29. #  The help file name is taken from environment variable "HELPFILE".  If
  30. #  HELPFILE is not in the environment, file "help" in the current
  31. #  directory is used.  A help file name specified in the -f option
  32. #  overrides.
  33. #
  34. #  The help files are formatted as follows:
  35. #
  36. #       default text lines
  37. #       -
  38. #       one
  39. #       item "one" text lines
  40. #       -
  41. #       two
  42. #       item "two" text lines
  43. #       ...
  44. #
  45. #  Sections are separated by lines containing a single "-".  Item names
  46. #  are the first line following a separator line.
  47. #
  48. ############################################################################
  49. #
  50. #  Links: options
  51. #
  52. ############################################################################
  53.  
  54.  
  55. link options
  56.  
  57.  
  58. procedure main(arg)
  59.    local defaultHelpFile, opts, fn, f, item, line, keywords, i, lline, k
  60.  
  61.    #
  62.    #  Initialize.
  63.    #
  64.    defaultHelpFile := "ihelp.dat"
  65.    opts := options(arg,"f:")
  66.    fn := \opts["f"] | "" ~== getenv("HELPFILE") | defaultHelpFile
  67.    f := open(fn) | stop("Can't open help file \"",fn,"\"")
  68.    #
  69.    #  Look for the specified section, if one was.
  70.    #
  71.    if item := map(arg[1]) then {
  72.       line := ""
  73.       until item == map(line[1:*item + 1]) do {
  74.      while read(f) ~== "-"
  75.      line := read(f) | stop("No help for ",item)
  76.      }
  77.       }
  78.    #
  79.    #  Output the section lines that contain the keywords.
  80.    #
  81.    write(line)
  82.    keywords := arg[2:0] | []
  83.    every i := 1 to *keywords do keywords[i] := map(keywords[i])
  84.    while "-" ~== (line := read(f)) do {
  85.       lline := map(line)
  86.       if not (every k := !keywords do if not find(k,lline) then break) then
  87.         write(line)
  88.       }
  89. end
  90.  
  91.